package vn.edu.uit.service.fetchers;

import org.json.JSONObject;

import vn.edu.uit.hotelbooking.JsonParse.RoomDetailParser;
import vn.edu.uit.hotelbooking.model.Room;
import vn.edu.uit.service.UITAPIContant;
import vn.edu.uit.service.UITHttpRequest;
import vn.edu.uit.service.UITHttpRequest.RequestMethod;
import vn.edu.uit.service.UITService;
import android.util.Log;

public class RoomDetailFetcher {
    private static final String LOG_TAG = "RoomDetailFetcher";
    private static final String TAG_ROOM_ID = "id";
    
    private static UITHttpRequest httpRequest; 
    
    public static Room getRoomDetail(String id) {
        UITService.REQUEST_SUCCESS = false;
        httpRequest=new UITHttpRequest(UITAPIContant.API_REST_DOMAIN_URL+UITAPIContant.Api_Functions.GET_ROOM_DETAIL);
        httpRequest.addParam(UITService.TAG_AUTHENTICATE, UITService.TOKEN);
        httpRequest.addParam(TAG_ROOM_ID, id);
        try {
            JSONObject object = httpRequest.doExecute(RequestMethod.POST);
            Log.d("JSON", object.toString());       
            if(object.getInt(UITService.TAG_ERROR)==0) {        //request was successful, return a province arraylist
                UITService.REQUEST_SUCCESS = true;
                return RoomDetailParser.getRoomDetailFromJson(object.getJSONArray(UITService.TAG_DATA));              
            } else {                                 //request was failed, return null
                UITService.REQUEST_SUCCESS = false;
                UITService.MSG = object.getString(UITService.TAG_MSG);
                return null;
            }   
        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.e(LOG_TAG, e.getMessage());
        }
        return null;
    }
}
